package com.ant.myagile.test.controller;



import javax.servlet.http.HttpServletResponse;

import grails.test.mixin.*

import org.junit.Before
import org.junit.Test
import org.springframework.mock.web.MockMultipartFile
import org.springframework.mock.web.MockMultipartHttpServletRequest
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.ant.myagile.Member
import com.ant.myagile.MemberController
import com.ant.myagile.MemberRole
import com.ant.myagile.MemberService
import com.ant.myagile.Role
import com.sun.net.httpserver.HttpServer;

@TestFor(MemberService)
@Mock([Member, Role, MemberRole])
class MemberServiceTest {
	MemberService memberService;
	Member currentMember;
	Role userRole;
	Role guestRole;
	def springSecurityService 
	
	@Before
	void setup(){
		springSecurityService = new Object()
		springSecurityService.metaClass.encodePassword = {String password -> "123456"}
		memberService = new MemberService();
		currentMember = new Member(username: "hieutest.lam@axonactive.vn", enabled: true, firstName: "HieuTest", lastName: "Lam Phuc", gender: "Male", company: "Axon Active Vietnam", skype: "phuchieuct", position: "Junior Java Developer", avatar: "2.jpg", mobile: "1239 911 602")
		currentMember.springSecurityService = springSecurityService
		currentMember.save()
		userRole = new Role(authority: "ROLE_USER").save(failOnError: true)
		guestRole = new Role(authority: "ROLE_GUEST").save(failOnError: true)
		MemberRole.create(currentMember, guestRole)
}
	
	@Test
	void testUpdateProfileFirstNameSuccessful(){
		String expected = "HieuTest Updated"
		Member member = Member.get(currentMember.id)
		member.firstName = expected
		member.save();
		String actual = member.firstName
		assertEquals(expected, actual);
		
	}
	
	
	@Test
	void testUpdateProfileLastNameSuccessful(){
		String expected = "Lam Phuc Updated"
		Member member = Member.get(currentMember.id)
		member.lastName = expected
		member.save();
		String actual = member.lastName
		assertEquals(expected, actual);
		
	}
	
	@Test
	void testUpdateProfileGenderSuccessful(){
		String expected = "Male Updated"
		Member member = Member.get(currentMember.id)
		member.gender = expected
		member.save();
		String actual = member.gender
		assertEquals(expected, actual);
		
	}
	
	@Test
	void testUpdateProfilePasswordSuccessful(){
		String expected = "Password Updated"
		Member member = Member.get(currentMember.id)
		member.password = expected
		member.save();
		String actual = member.password
		assertEquals(expected, actual);
		
	}
	
	@Test
	void testUpdateProfileSkypeSuccessful(){
		String expected = "Skype Updated"
		Member member = Member.get(currentMember.id)
		member.skype = expected
		member.save();
		String actual = member.skype
		assertEquals(expected, actual);
		
	}
	
	@Test
	void testUpdateProfileMobileSuccessful(){
		String expected = "Mobile Updated"
		Member member = Member.get(currentMember.id)
		member.mobile = expected
		member.save();
		String actual = member.mobile
		assertEquals(expected, actual);
		
	}

	@Test
	void testUpdateProfileAvatarSuccessful(){
		String expected = "Avatar Updated"
		Member member = Member.get(currentMember.id)
		member.avatar = expected
		member.save();
		String actual = member.avatar
		assertEquals(expected, actual);
		
	}
	
	
	@Test
	void testUpdateProfileCompanySuccessful(){
		String expected = "Avatar Updated"
		Member member = Member.get(currentMember.id)
		member.company = expected
		member.save();
		String actual = member.company
		assertEquals(expected, actual);
		
	}
	
	
	
	
	
	
	
		
	
	
	
	
}
